package br.mg.bhe.ftpobre.gui.popup;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;

import br.mg.bhe.ftpobre.command.DeleteLocalFileCommand;
import br.mg.bhe.ftpobre.command.facade.DeleteFileFacade;
import br.mg.bhe.ftpobre.command.facade.FileFacade;
import br.mg.bhe.ftpobre.command.facade.ServerFacade;

/**
 * 
 * @author Aureliano
 */
@SuppressWarnings("serial")
public class LocalFilePopup extends JPopupMenu {
	
	private JMenuItem upload;
	private JMenuItem open;
	private JMenuItem delete;
	private JMenuItem properties;
	
	public LocalFilePopup() {
		this.init();
		this.addItems();
	}

	private void init() {
		this.upload = new JMenuItem("Upload");
		this.open = new JMenuItem("Abrir");
		this.delete = new JMenuItem("Excluir");
		this.properties = new JMenuItem("Propriedades");
		
		this.upload.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				uploadAction();
			}
		});
		
		this.open.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				openAction();
			}
		});
		
		this.delete.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				deleteAction();
			}
		});
		
		this.properties.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				propertiesAction();
			}
		});
	}

	private void addItems() {
		super.add(this.upload);
		super.add(new JSeparator());
		super.add(this.open);
		super.add(this.delete);
		super.add(new JSeparator());
		super.add(this.properties);
	}
	
	private void uploadAction() {
		ServerFacade.upload();
	}
	
	private void openAction() {
		FileFacade.openFile();
	}
	
	private void deleteAction() {
        DeleteFileFacade.deleteFile(DeleteLocalFileCommand.class);
	}
	
	private void propertiesAction() {
		FileFacade.showProperties(true);
	}
}